﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="NodeTests.cs" company="dimamartovoi">
//   Apache License
//   Version 2.0, January 2004
//   http://www.apache.org/licenses
// </copyright>
// <summary>
//   Defines the NodeTests type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

using System.Collections.Generic;
using System.Diagnostics;

using ActorModel.Engine.Core;

using NUnit.Framework;

namespace Engine.Tests
{
    [TestFixture]
    public class NodeTests
    {
        [Test]
        [Ignore("obsolete.")]
        public void NodeEvolution()
        {
//            var connector1 = new Connector<int>(0, 1, 3);
//            connector1.StateReceived += this.ConnectorOnStateReceived;
//            var connector2 = new Connector<int>(5, 2, 4);
//            connector2.StateReceived += this.ConnectorOnStateReceived;
//            var node1Connectors = new List<Connector<int>> { connector1, connector2 };
//            var node1 = new Node<int>(0, 100, node1Connectors, this.EvolutionFunc);
//
//            var connector3 = new Connector<int>(10, 3, 1);
//            connector3.StateReceived += this.ConnectorOnStateReceived;
//            var connector4 = new Connector<int>(15, 4, 2);
//            connector4.StateReceived += this.ConnectorOnStateReceived;
//            var node2Connectors = new List<Connector<int>> { connector3, connector4 };
//            var node2 = new Node<int>(1, 200, node2Connectors, this.EvolutionFunc);
//
//            node1.NodeStateChanged += this.NodeOnStateChanged;
//            node2.NodeStateChanged += this.NodeOnStateChanged;
//
//            Debug.WriteLine(node1);
//            Debug.WriteLine(node2);
//
//            node1.Evolute();
//            Assert.AreEqual(node1.State, 95);
//            node2.Evolute();
//            Assert.AreEqual(node2.State, 185);
//
//            node1.Evolute();
//            Assert.AreEqual(node1.State, 95 - 185);
//            node2.Evolute();
//            Assert.AreEqual(node2.State, 185 - 95);
        }

        private void ConnectorOnStateReceived(ConnectorStateEventArgs<int> connectorStateEventArgs)
        {
            Debug.WriteLine(
                "connector with id = [{0}] received state data: [{1}]", 
                connectorStateEventArgs.SourceId, 
                connectorStateEventArgs.State);
        }

        private IEnumerable<int> EvolutionFunc(int nodeState, IEnumerable<int> connectorsState)
        {
            return new int[5];
        }

        private void NodeOnStateChanged(NodeStateChangedEventArgs<int> nodeStateChangedEventArgs)
        {
            Debug.WriteLine(
                "node with id = [{0}] changed states to: [{1}]", 
                nodeStateChangedEventArgs.Node.Id, 
                nodeStateChangedEventArgs.State);
        }
    }
}